Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Using an interface definition

Interfaces cannot be instantiated but they can be used as the data type to define an object reference, such as in a DEFINE VARIABLE statement or a DEFINE PARAMETER statement. The value of the object reference can then be assigned to be an instance of a class that implements the interface. Multiple classes can implement the same interface, which allows the classes to be treated in a common manner. An object reference to an interface can be used to call these common methods even though the underlying objects are of different classes. This is similar to having multiple classes inheriting from the same super class although an interface provides no method implementation. An object reference to the super class can be used to call the methods that are defined in the super class, even though the underlying objects are of different classes.

The following example shows a simple interface definition:

INTERFACE acme.myObjs.Interfaces.IBusObj: 
    METHOD PUBLIC VOID printObj ( ). 
    METHOD PUBLIC VOID logObj (INPUT filename AS CHARACTER). 
END INTERFACE. 

This shows part of the sample class definition modified to implement the interface:

CLASS acme.myObjs.CustObj INHERITS acme.myObjs.Common.CommonObj 
    IMPLEMENTS acme.myObjs.Interfaces.IBusObj: 
... 
/* Must implement methods defined in the interface */ 
    METHOD PUBLIC VOID printObj( ): 
        OUTPUT TO PRINTER. 
        ... 
        OUTPUT CLOSE. 
    END METHOD. 
    METHOD PUBLIC VOID logObj(INPUT fileName AS CHARACTER): 
        DEFINE VARIABLE i AS INTEGER NO-UNDO. 
        OUTPUT TO VALUE(fileName). 
        ... 
        OUTPUT CLOSE. 
    END METHOD. 
END CLASS. 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095